package user;

import book.BookList;
import ioperation.IOperation;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-05-23
 * Time: 20:13
 */
public abstract class User {
    protected String name;

    protected IOperation[] iOperations;

    public User(String name) {
        this.name = name;
    }

    public abstract int menu();

    public void doOperation(int choice, BookList bookList) {
        if(choice == 5) {
            System.out.println();
            int sortType = -1;
            System.out.println("请选择您想要的排序方式：1->按价格排序  2->按书名排序");
            Scanner scanner = new Scanner(System.in);

            do {
                sortType = scanner.nextInt();
                if(sortType != 1 && sortType != 2) {
                    System.out.println("输入错误，请重写输入！");
                }
                if(sortType == 2) {
                    this.iOperations[choice + 1].work(bookList);
                    return;
                }
            }while (sortType != 1 && sortType != 2);

        }
        this.iOperations[choice].work(bookList);
    }

}
